package com.gimi.cloud.jimi.client.service.userInfo.impl;

import com.gimi.cloud.jimi.client.service.userInfo.RdJxlService;
import com.gimi.cloud.jimi.dao.dao.userInfo.RdJxlDao;
import com.gimi.cloud.jimi.dto.userInfo.RdJxlDTO;
import com.gimi.cloud.jimi.entity.userInfo.RdJxl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RdJxlServiceImpl implements RdJxlService {
    @Autowired
    private RdJxlDao rdJxlDao;

    @Override
    public void saveRdJxl(RdJxl jxl) {
        if(jxl.getjId() != null && jxl.getjId().intValue() > 0) {
            rdJxlDao.updateByPrimaryKey(jxl);
        } else {
            rdJxlDao.insert(jxl);
        }
    }

    @Override
    public RdJxl getNewestJxlByUser(Integer userId) {
        return rdJxlDao.getNewestJxlByUser(userId);
    }

	@Override
	public Map<String, Object> getAuthenticationInfo(Integer userId) {
		Map<String, Object> map = new HashMap<>();
		RdJxl jxlDTO = rdJxlDao.getNewestJxlByUser(userId);
		//无数据
		if (jxlDTO == null) {
			map.put("status", 0);
			return map;
		}
		RdJxlDTO effectionJxl = rdJxlDao.isEffection(userId);
		//有数据未过期
		if (jxlDTO != null && effectionJxl != null ) {
			map.put("status", 1);
			map.put("data", effectionJxl);
			return map;
		}else {
			map.put("status", 2);
			return map;
		}
	}
}
